using Headsight.BPMN2WF.BPMN.Model;
using Headsight.BPMN2WF.BPMN.Schemas;
using Headsight.BPMN2WF.Transformation.Transformers;

namespace Headsight.BPMN2WF.Transformation.BPMN2TransformerMappings
{
    /// <summary>
    /// <see cref="IBPMN2WFTransformations"/> default implementation.
    /// </summary>
    public class BPMN2WFTransformationsSimple : IBPMN2WFTransformations
    {
        public IBPMN2WFTransformation Get(BPMNFlowNode flowNode)
        {
            //
            // Time for some better mappings. Our customer wants us to 
            // map BPMN 2.0 user tasks to a specific custom developed WF4.x
            // user task interacting with his platform. Same for BPMN 2.0 end events...
            //
            // Notice the IBPMN2WFTransformationMappings interface! We can develop
            // - for example - a XML or command line based implementation of 
            // IBPMN2WFTransformationMappings as well. The XML configuration files
            // could be - for example - customer specific. 
            //

            var typeOfFlowElement = flowNode.TElement.GetType();

            if (typeof(tGateway).IsAssignableFrom(typeOfFlowElement))
            {
                return new BPMN2WFTransformationExclusiveGateway();
            }

            // Let BPMN2WFTransformation_CustomWFUserTask perform transformation
            // of BPMN user task to WF4.x.
            if (typeOfFlowElement == typeof(tUserTask))
            {
                return new BPMN2WFTransformationCustomWFUserTask();
            }

            // Let BPMN2WFTransformation_TerminateEndEvent perform transformation
            // of BPMN end event to WF4.x.
            if (typeOfFlowElement == typeof(tEndEvent))
            {
                return new BPMN2WFTransformationTerminateEndEvent();
            }

            // No mapping found? Use default transformations strategy (in future of course
            // the default transformation strategies are not using WF4.x WriteLine but
            // better suited WF4.x activities.
            return new BPMN2WFTransformationWriteLine();
        }
    }
}